// Bachelor of Software Engineering 
// Media Design School 
// Auckland
// New Zealand
// 
// (c) 2005 - 2014 Media Design School 
// 
// File Name : Move.cpp
// Description : Move implementation
// Author : Serge Radinovich
// Mail : srad015@hotmail.com

#pragma once

#include "Move.h"

////////////////////////////
//Constructor
//Sets up all data needed to use a Move to undo player's actions
///////////////////////////
Move::Move(std::list<Card*>* _pPileMovedTo, 
	       std::list<Card*>* _pCardsMoved, 
		   const int _iCardCount, 
		   std::list<Card*>* _pPileMovedFrom,
		   CardPileGroup* _pPileGroupMovedFrom, 
		   bool _bFlip)
{
	m_bFlip = _bFlip;
	m_pPileMovedTo = _pPileMovedTo;
	m_pPileMovedFrom = _pPileMovedFrom;
	m_pPileGroupMovedFrom = _pPileGroupMovedFrom;

	if(_pCardsMoved == nullptr)
	{
		m_pCardsMoved = nullptr;
		return;
	}

	auto _iter = _pCardsMoved->end();
	for(int i =0 ; i < _iCardCount; i++)
	{
		_iter--;
	}

	m_pCardsMoved = new std::list<Card*>;
	while(_iter != _pCardsMoved->end())
	{
		m_pCardsMoved->push_back((*_iter));
		_iter++;
	}
}

////////////////////////////
//Destructor
///////////////////////////
Move::~Move(void)
{
	if(m_pCardsMoved == nullptr)
	{
		return;
	}
	while(!m_pCardsMoved->empty())
	{
		m_pCardsMoved->pop_back();
	}
	delete m_pCardsMoved;
}


////////////////////////////
//Constructor 
///////////////////////////
StockMove::StockMove(bool _bStockEmpty, bool _bWasteEmpty, 
			         std::list<Card*>* _pPileMovedTo, std::list<Card*>* _pCardsMoved,
					 const int _iCardCount, std::list<Card*>* _pPileMovedFrom, CardPileGroup* _pPileGroupMovedFrom, bool _bFlip)
					 :
					 Move(_pPileMovedTo, _pCardsMoved, _iCardCount, _pPileMovedFrom, _pPileGroupMovedFrom),
					 m_bStockEmpty(_bStockEmpty), m_bWasteEmpty(_bWasteEmpty), m_iCardCount(_iCardCount)
{

}

////////////////////////////
//Destructor
///////////////////////////
StockMove::~StockMove(void)
{
}